package functions.ems_payment;

import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.beans.QueryPayPrepareInfoBean;
import com.crc.mam.PropertiesUtil;

import coms.Constants;
import frame.HttpHelper;
/**
 * 
 * @author zhuyi
 * 付款准备查询的分页查询以及排序功能
 */
public class QueryPayPrepareInfo {
	private static Logger logger = LoggerFactory.getLogger(QueryPayPrepareInfo.class);
	String companyCode =null;
	String claimNo;
	String result =null;
	String invoiceNo=null;
	String branchNo=null;
	String status=null;
	String vendorType=null;
	String vendorName=null;
	String payWay=null;
	String lefiAmount=null;
	String rightAmount=null;
	String startDate=null;
	String endDate=null;
	String projectCode=null;
	String currency=null;
	QueryPayPrepareInfoBean queryPayPrepareInfoBean;
	
	
	public QueryPayPrepareInfo(String crctoken,String claimNo) {
		super();
		this.claimNo = claimNo;
		
	}

	/**
	 * 准备付款查询
	 */
	public void payPerpareInfo() {
		logger.info("通过付款申请单号"+branchNo+"查询准备付款------------开始");
		String params = "{\"page\":{\"currentPage\":1,\"pageSize\":10,\"recordCount\":6},"
				+ "\"params\":{\"ouCode\":\"\",\"claimNo\":\"\",\"ouName\":\"\","
				+ "\"branchNo\":\""+branchNo+"\",\"invoiceNo\":\"\",\"status\":\"\",\"vendorType\":\"\","
				+ "\"vendorName\":\"\",\"payWay\":\"\",\"leftAmount\":\"\",\"rightAmount\":\"\","
				+ "\"date\":[\"\",\"\"],\"startDate\":\"\",\"endDate\":\"\",\"projectCode\":\"\","
				+ "\"currency\":\"\"},\"sortDTO\":{\"fieldName\":\"\",\"orderBy\":\"\"}}";
		
		String url = Constants.PRE_PARE_INFO_URL;
		try {
			result = HttpHelper.post(params, url);
			logger.info("payPerpareInfo"+result);
			try {
				JSONObject jsonObject = new JSONObject(result);
				JSONArray array = jsonObject.getJSONArray("list");
				for(int i=0;i<array.length();i++) {
					JSONObject object = (JSONObject) array.get(i);
					String applyEmpId="";
					try {
						applyEmpId = object.getString("applyEmpId");
					} catch (Exception e) {
						// TODO: handle exception
					}
					Integer applyPaymentAmount=0;
					try {
						applyPaymentAmount= object.getInt("applyPaymentAmount");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String branchNo="";
					try {
						branchNo=object.getString("branchNo");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String claimNo="";
					try {
						claimNo=object.getString("claimNo");
					}catch (Exception e) {
						// TODO: handle exception
					}
					String companyCode="";
					try {
						companyCode=object.getString("companyCode");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String companyName="";
					try {
						companyCode=object.getString("companyCode");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String createdBy="";
					try {
						createdBy=object.getString("createdBy");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String createdTime="";
					try {
						createdTime= object.getString("createdTime");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String endDate="";
					try {
						endDate= object.getString("endDate");
					} catch (Exception e) {
						// TODO: handle exception
					}
					Integer id=0;
					try {
						id=object.getInt("id");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String invoiceNo="";
					try {
						invoiceNo=object.getString("invoiceNo");
					} catch (Exception e) {
						// TODO: handle exception
					}
					Integer leftAmount=0;
					try {
						leftAmount=object.getInt("leftAmount");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String  leftPayDate="";
					try {
						leftPayDate=object.getString("leftPayDate");
					} catch (Exception e) {
						// TODO: handle exception
					}
					Integer matchAmount=0;
					try {
						matchAmount=object.getInt("mathcAmount");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String payStatus="";
					try {
						payStatus=object.getString("payStatus");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String payWay="";
					try {
						payWay=object.getString("payWay");
					} catch (Exception e) {
						// TODO: handle exception
					}
					Integer rightAmount=0;
					try {
						rightAmount=object.getInt("rightAmount");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String rightpayDate="";
					try {
						rightpayDate=object.getString("rightPayDate");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String startDate="";
					try {
						startDate=object.getString("startDate");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String status="";
					try {
						status=object.getString("status");
					} catch (Exception e) {
						// TODO: handle exception
					}
					Integer unMatchAmount=0;
					try {
						unMatchAmount=object.getInt("unMathcAmount");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String vendorName="";
					try {
						vendorName=object.getString("vendorName");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String vendorType="";
					try {
						vendorType=object.getString("vendorType");
					} catch (Exception e) {
						// TODO: handle exception
					}
					queryPayPrepareInfoBean = new QueryPayPrepareInfoBean(applyEmpId, applyPaymentAmount, branchNo, claimNo, 
							companyCode, companyName, createdBy, createdTime, endDate, id, invoiceNo, leftAmount,
							leftPayDate, matchAmount, payStatus, payWay, rightAmount, rightpayDate, startDate, status, 
							unMatchAmount, vendorName, vendorType);
					System.out.println(queryPayPrepareInfoBean.toString());		
					
				}
			} catch (Exception e) {
				e.printStackTrace();
			}	
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
